from proj03 import ssh_output
import configparser
import time
import logging

conf = configparser.ConfigParser()
conf.read('backup.config',encoding='utf-8')
logging.basicConfig(level=logging.INFO,
                    format="%(asctime)s %(name)s %(levelname)s %(message)s",
                    datefmt = '%Y-%m-%d  %H:%M:%S %a',   #注意月份和天数不要搞乱了，这里的格式化符与time模块相同
                    filemode = 'a' ,
                    filename = "{}".format(conf['main']['logfile'])
                    )
jobtime = conf['main']['jobtime']
file1  = open('list.txt', 'r', encoding='utf-8')
file_line = file1.readlines()
file1.close()
while True:
    time_now_hm = time.strftime("%H:%M:%S", time.localtime())
    logging.debug(time_now_hm)
    if 1:
        timelog = str(time.strftime("%Y_%m_%d", time.localtime()))
        logging.info("开始执行备份...")
        for i in file_line:
            ip = i.split(':')[0]
            manu_f = i.split(':')[1].strip()
            username = conf[manu_f]['username']
            password = conf[manu_f]['password']
            logging.debug("设备登陆账号密码为{}  {}".format(username, password))
            ssh_output.main(ip,username,password,manu_f,timelog)
    time.sleep(1)
    break
